package com.game.module.skill
{
	import com.dusk.util.TextUtil;
	import com.game.data.vo.PlayerDataVO;
	import com.game.data.vo.SkillVO;
	import com.game.view.component.ComponentBase;
	import flash.text.TextField;
	import flash.text.TextFormatAlign;
	
	public class SinglePassiveSkill extends ComponentBase
	{
		public function SinglePassiveSkill()
		{
			super();
		}
		
		private var player:PlayerDataVO;
		private var skillVo:SkillVO;
		private var skillName:TextField;
		private var skillLevel:TextField;
		private var currentAttribute:TextField;
		private var nextAttribute:TextField;
		private var needLhValue:TextField;
		
		override protected function beforeAdded():void
		{
			skillName = TextUtil.creatTextField("",TextUtil.UNIVERSAL_FONT,17,TextFormatAlign.CENTER,0xFFFFFF,false,false);
			skillLevel = TextUtil.creatTextField("",TextUtil.UNIVERSAL_FONT,17,TextFormatAlign.CENTER,0xFFFFFF,false,false);
			currentAttribute = TextUtil.creatTextField("",TextUtil.UNIVERSAL_FONT,17,TextFormatAlign.CENTER,0xFFFFFF,false,false);
			nextAttribute = TextUtil.creatTextField("",TextUtil.UNIVERSAL_FONT,17,TextFormatAlign.CENTER,0xFFFFFF,false,false);
			needLhValue = TextUtil.creatTextField("",TextUtil.UNIVERSAL_FONT,17,TextFormatAlign.CENTER,0xFFFFFF,false,false);
			skillName.y = skillLevel.y = currentAttribute.y = nextAttribute.y = needLhValue.y = 0;
			skillName.x = 4;
			skillName.width = 58;
			skillLevel.x = 87;
			skillLevel.width = 58;
			currentAttribute.x = 165;
			currentAttribute.width = 167;
			nextAttribute.x = 345;
			nextAttribute.width = 177;
			needLhValue.x = 645;
			needLhValue.width = 80;
			addChild(skillName);
			addChild(skillLevel);
			addChild(currentAttribute);
			addChild(nextAttribute);
			addChild(needLhValue);
		}
		
		public function setSkillVo(vo:SkillVO):void
		{
			skillVo = vo;
		}
		
		public function setPlayer(dataVO:PlayerDataVO):void
		{
			player = dataVO;
		}
		
		public function refreshPanel():void
		{
			skillName.text = skillVo.skillName;
			skillLevel.text = player.getPassiveSkillLevelByIndex(skillVo.groupIndex) + "级";
			currentAttribute.text = getDescription(player.getPassiveSkillLevelByIndex(skillVo.groupIndex));
			nextAttribute.text = getDescription(player.getPassiveSkillLevelByIndex(skillVo.groupIndex) + 1);
			needLhValue.text = player.getPassiveSkillLevelByIndex(skillVo.groupIndex) >= skillVo.maxLevel ? "已达上限" : skillVo.getUpGradeCostByLevel(player.getPassiveSkillLevelByIndex(skillVo.groupIndex) + 1).toString();
		}
		
		private function getDescription(level:int):String
		{
			if(level > skillVo.maxLevel)
			{
				return "已达到最高等级";
			}
			if(level == 0)
			{
				return "无加成";
			}
			var num:int = skillVo.getSkillHurtByLevel(level);
			switch (skillVo.groupIndex)
			{
				case 1:
					return "生命上限增加 " + num + "点";
				case 2:
					return "魔法上限增加 " + num + "点";
				case 3:
					return "暴击率增加 " + num + " %";
				case 4:
					return "每秒回血增加 " + num + "点";
				case 5:
					return "每秒回蓝增加 " + num + "点";
				default:
					return "未知技能";
			}
		}
		
		override protected function onRemoved():void
		{
			player = null;
			skillVo = null;
		}
	}
}
